package com.qf.ssm.dto;

import com.fasterxml.jackson.annotation.JsonInclude;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class R {

    private int code;//错误码
    private String msg;//描述
    private Object data;//携带的数据

    public static R setOk(){
        return setOk(null);
    }

    public static R setOk(Object data){
        R r = new R();
        r.setCode(1);
        r.setData(data);
        r.setMsg("成功");
        return r;
    }
    public static R setError(){
        return setError(null);
    }

    public static R setError(Object data){
        return setError(0,"请检查网络",data);
    }

    private static R setError(int code,String msg,Object data){
        R r = new R();
        r.setCode(code);
        r.setData(data);
        r.setMsg(msg);
        return r;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
